﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySpace.Data;
using System.Data;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bdnews(huodong_list,9, "BigClassId=2");
            bdnews(gonggao_list, 9, "BigClassId=1");
            bddengxin(dengxin_list, 17);
            bdxuyuan(xuyuan_list, 10);
            bdliuyan(liuyan_list,9);
        }
    }
    protected void bdnews(Repeater rp, int row_count, string filter)
    {
        DBHandler dbh = GetHandler.Init();
        if (!string.IsNullOrEmpty(filter))
        {
            filter = "and " + filter;
        }
        dbh.CommandText = string.Format("select top {0} * from news where ShenHe=1 {1} order by id desc", row_count, filter);
        rp.DataSource = dbh.ExecuteDataTable();
        rp.DataBind();
    }
    protected void bddengxin(Repeater rp, int row_count)
    {
        Random rnd = new Random(unchecked((int)DateTime.Now.Ticks));
        int intRandomNumber = rnd.Next();
        DBHandler dbh = GetHandler.Init();
        dbh.CommandText = string.Format("select top {0} * from DengXinArticle where ShenHe=1 order by Rnd(" + (-1 * intRandomNumber) + "*id)", row_count);
        rp.DataSource = dbh.ExecuteDataTable();
        rp.DataBind();
    }
    protected void bdxuyuan(Repeater rp,int row_count)
    {
        Random rnd = new Random(unchecked((int)DateTime.Now.Ticks));
        int intRandomNumber = rnd.Next();
        DBHandler dbh = GetHandler.Init();
        dbh.CommandText = string.Format("select top {0} * from WishingWall order by Rnd(" + (-1 * intRandomNumber) + "*id)", row_count);
        rp.DataSource = dbh.ExecuteDataTable();
        rp.DataBind();
    }
    protected void bdliuyan(Repeater rp, int row_count)
    {
        DBHandler dbh = GetHandler.Init();
        dbh.CommandText = string.Format("select top {0} * from hwguestbook where len(reply) > 0 or IsTop = 1  order by id desc", row_count);
        rp.DataSource = dbh.ExecuteDataTable();
        rp.DataBind();
    }
    protected string getFlashData()
    {
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath(@"~/XML/EmbedSwfData.xml"));
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            sb.Append("<a image='" + ds.Tables[0].Rows[i]["img"] + "?r=" + ds.Tables[0].Rows[i]["rand"] + "' info='" + ds.Tables[0].Rows[i]["title"] + "' url='" + ds.Tables[0].Rows[i]["url"] + "' />");
        }
        return sb.ToString();
    }
}